const url = require("url");
// console.log(url)

// 解析url字符
const str = "http://www.baidu.com:3000/abc/asd?kd=上海&key=1q344#top";
console.log( url.parse(str, true) );

// 解析url对象
const urlObj = {
  protocol: 'http:',
  slashes: true,
  auth: null,
  host: 'www.baidu.com:3000',
  port: '3000',
  hostname: 'www.baidu.com',
  hash: '#top',
  search: '?kd=上海&key=1q344',
  query: { kd: '上海', key: '1q344' },
  pathname: '/abc/asd',
  path: '/abc/asd?kd=上海&key=1q344',
  href: 'http://www.baidu.com:3000/abc/asd?kd=上海&key=1q344#top'
}
console.log( url.format(urlObj) )



